package org.example.mqcreate;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import static org.example.constant.mqConstant.*;

/**
 * 创建交换机和队列
 */
@Component
public class UserOperateMQ {

    /**
     * 创建交换机
     */
    @Bean
    public DirectExchange userOperateExchange() {
        return new DirectExchange(USER_EXCHANGE_NAME);
    }

    /**
     * 新增用户队列
     */
    @Bean
    public Queue addUserQueue() {
        return new Queue(ADDUSER_QUEUE);
    }

    /**
     * 修改用户队列
     */
    @Bean
    public Queue editUserQueue() {
        return new Queue(EDITUSER_QUEUQ);
    }

    /**
     * 新增队列与交换机绑定
     */
    @Bean
    public Binding bindingAddUserQueue() {
        return BindingBuilder.bind(addUserQueue()).to(userOperateExchange()).with(ADD_KEY);
    }

    /**
     * 修改队列与交换机绑定
     */
    @Bean
    public Binding bindingEditUserQueue() {
        return BindingBuilder.bind(editUserQueue()).to(userOperateExchange()).with(EDIT_KEY);
    }
}
